package cn.demoxy.service.impl;

import cn.demoxy.model.dto.DemoDataConfDTO;
import cn.demoxy.model.entity.DemoDataConf;
import cn.demoxy.mapper.DemoDataConfMapper;
import cn.demoxy.model.entity.DemoTenant;
import cn.demoxy.service.IDemoDataConfService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 数据源表 业务实现类
 * @author demo
 * @date 2022-05-24
 */
@Service
public class DemoDataConfServiceImpl extends ServiceImpl<DemoDataConfMapper, DemoDataConf> implements IDemoDataConfService {

    @Override
    public Page<DemoDataConf> findAllDataSource(DemoDataConfDTO dataConfDTO) {
        //创建page对象，传递当前页，每页记录数
        Page<DemoDataConf> page = new Page<>(dataConfDTO.getCurrent(), dataConfDTO.getSize());
        //构建条件
        QueryWrapper<DemoDataConf> wrapper = new QueryWrapper<>();
        //根据数据源名称查询
        if (StringUtils.hasText(dataConfDTO.getName())) {
            wrapper.like("name", dataConfDTO.getName());
        }
        //调用方法实现分页查询
        Page<DemoDataConf> dataConfPages = baseMapper.selectPage(page, wrapper);
        //返回结果
        return dataConfPages;
    }
}
